home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWContxt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  12.6 KB  |  416 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWContxt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWCONTXT_H
  13. #include "FWContxt.h"
  14. #endif
  15.  
  16. #ifndef FWVIEW_H
  17. #include "FWView.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWPRIDEB_H
  25. #include "FWPriDeb.h"
  26. #endif
  27.  
  28. #ifndef FWACQUIR_H
  29. #include "FWAcquir.h"
  30. #endif
  31.  
  32. #ifndef FWFCTINF_H
  33. #include "FWFctInf.h"
  34. #endif
  35.  
  36. #ifndef FWODGEOM_H
  37. #include "FWODGeom.h"
  38. #endif
  39.  
  40. #ifndef FWUTIL_H
  41. #include "FWUtil.h"
  42. #endif
  43.  
  44. #ifndef FWSOMENV_H
  45. #include "FWSOMEnv.h"
  46. #endif
  47.  
  48. // ----- OpenDoc Includes -----
  49.  
  50. #ifndef SOM_ODFacet_xh
  51. #include <Facet.xh>
  52. #endif
  53.  
  54. //========================================================================================
  55. // Runtime Informations
  56. //========================================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment framework
  60. #endif
  61.  
  62. //========================================================================================
  63. //    class FW_CWindowContext
  64. //========================================================================================
  65.  
  66. FW_DEFINE_AUTO(FW_CWindowContext)
  67.  
  68. //----------------------------------------------------------------------------------------
  69. //    FW_CWindowContext::FW_CWindowContext
  70. //----------------------------------------------------------------------------------------
  71.  
  72. FW_CWindowContext::FW_CWindowContext(Environment* ev, ODFacet* odFacet) :
  73.     FW_CGraphicContext(ev),
  74.     fTempDevice(NULL),
  75.     fODWindow(NULL)
  76. {
  77.     InitWindowContext(ev, odFacet->GetWindow(ev));
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    FW_CWindowContext::FW_CWindowContext
  82. //----------------------------------------------------------------------------------------
  83.  
  84. FW_CWindowContext::FW_CWindowContext(Environment* ev, ODWindow *odWindow) :
  85.     FW_CGraphicContext(ev),
  86.     fTempDevice(NULL),
  87.     fODWindow(NULL)
  88. {
  89.     InitWindowContext(ev, odWindow);
  90. }
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    FW_CWindowContext::InitWindowContext
  94. //----------------------------------------------------------------------------------------
  95.  
  96. void FW_CWindowContext::InitWindowContext(Environment* ev, ODWindow *odWindow)
  97. {
  98.     FW_ASSERT(odWindow != NULL);
  99.     fODWindow = odWindow;
  100.     fODWindow->Acquire(ev);
  101.     
  102.     ODFacet *facet = fODWindow->GetRootFacet(ev);
  103.  
  104.     FW_CAcquiredODShape aqClipShape = AcquireClipShape(ev);
  105.  
  106. /*
  107.     [HLX] there is a problem trying to reuse the graphic device of the root frame. 
  108.     First of all if the graphic device has a fContext, it should be suspended. Also
  109.     now that we are running static part I don't know what the effect is. We need to 
  110.     look at that. Might be able to put it back when we move the graphic to a SOM DLL.
  111.     
  112.     FW_CGraphicDevice* device = FW_GetFacetGraphicDevice(ev, facet);
  113.     if (device == NULL)
  114.     {
  115.         fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
  116.         device = fTempDevice;
  117.     }
  118.  
  119.     InitGraphicContext(device,
  120.                         NULL,
  121.                         aqClipShape);
  122. */
  123.     
  124.     fTempDevice = FW_PrivGDev_CreateFromODCanvas(ev, facet->GetCanvas(ev));
  125.     FW_FailOnEvError(ev);
  126.     
  127.     InitGraphicContext(fTempDevice,
  128.                         NULL,
  129.                         aqClipShape);
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    FW_CWindowContext::~FW_CWindowContext
  134. //----------------------------------------------------------------------------------------
  135.  
  136. FW_CWindowContext::~FW_CWindowContext()
  137. {
  138.     
  139.     if (fODWindow)
  140.     {
  141.         FW_SOMEnvironment ev;
  142.         fODWindow->Release(ev);
  143.     }
  144.     
  145.     if (fTempDevice)
  146.         FW_PrivGDev_Release(fTempDevice);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    FW_CWindowContext::AcquireClipShape
  151. //----------------------------------------------------------------------------------------
  152.  
  153. ODShape* FW_CWindowContext::AcquireClipShape(Environment* ev)
  154. {
  155. #ifdef FW_BUILD_MAC
  156.     FW_CRect rect(fODWindow->GetPlatformWindow(ev)->portRect);
  157. #endif
  158. #ifdef FW_BUILD_WIN
  159.     FW_CPlatformRect clientRect;
  160.     ::GetClientRect(fODWindow->GetPlatformWindow(ev), &clientRect);
  161.     FW_CRect rect(clientRect);
  162. #endif
  163.  
  164.     return ::FW_NewODShape(ev, rect);
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CWindowContext::Reset
  169. //----------------------------------------------------------------------------------------
  170.  
  171. void FW_CWindowContext::Reset()
  172. {
  173.     FW_CAcquiredODShape aqClipShape = AcquireClipShape(fEnvironment);    
  174.     PrivReset(NULL, aqClipShape);
  175. }
  176.  
  177. //========================================================================================
  178. //    class FW_CFrameContext
  179. //========================================================================================
  180.  
  181. FW_DEFINE_AUTO(FW_CFrameContext)
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // FW_CFrameContext::FW_CFrameContext
  185. //----------------------------------------------------------------------------------------
  186. // invalidShape is in Frame coordinate
  187.  
  188. FW_CFrameContext::FW_CFrameContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
  189.     FW_CGraphicContext(ev),
  190.     fFacet(facet)
  191. {
  192.     FW_ASSERT(facet != NULL);
  193.     
  194.     FW_CAcquiredODTransform aqFrameTransform = facet->AcquireFrameTransform(ev, NULL);
  195.     
  196.     FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL));
  197.     if (invalidShape != NULL)
  198.         aqClipShape->Intersect(ev, invalidShape);
  199.  
  200.     InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet),
  201.                         aqFrameTransform,
  202.                         aqClipShape);
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CFrameContext::~FW_CFrameContext
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_CFrameContext::~FW_CFrameContext()
  210. {
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    FW_CFrameContext::Reset
  215. //----------------------------------------------------------------------------------------
  216.  
  217. void FW_CFrameContext::Reset()
  218. {
  219.     FW_CAcquiredODTransform aqContentTransform = fFacet->AcquireFrameTransform(fEnvironment, NULL);
  220.     FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(fEnvironment, fFacet->AcquireAggregateClipShape(fEnvironment, NULL));
  221.     
  222.     PrivReset(aqContentTransform, aqClipShape);
  223. }
  224.  
  225. //========================================================================================
  226. //    class FW_CPlatformGraphicContext
  227. //========================================================================================
  228.  
  229. FW_DEFINE_AUTO(FW_CPlatformGraphicContext)
  230.  
  231. //----------------------------------------------------------------------------------------
  232. // FW_CPlatformGraphicContext::FW_CPlatformGraphicContext
  233. //----------------------------------------------------------------------------------------
  234.  
  235. FW_CPlatformGraphicContext::FW_CPlatformGraphicContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
  236.     FW_CGraphicContext(ev),
  237.     fFacet(facet)
  238. #ifdef FW_BUILD_MAC
  239.     ,fMacPort(NULL)
  240. #endif
  241. {
  242.     FW_ASSERT(facet != NULL);
  243.  
  244.     // InitGraphicContext expect clip shape in content coordinates
  245.     FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
  246.     FW_FrameToContent(ev, fFacet->GetFrame(ev), aqClipShape);
  247.     
  248.     if (invalidShape != NULL)
  249.         aqClipShape->Intersect(ev, invalidShape);
  250.  
  251.     InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet),
  252.                         NULL,
  253.                         aqClipShape);
  254.                         
  255. #ifdef FW_BUILD_MAC
  256.     PrivMacAlignOrigin(ev);
  257. #endif
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. // FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext
  262. //----------------------------------------------------------------------------------------
  263.  
  264. FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext()
  265. {
  266. #ifdef FW_BUILD_MAC
  267.     if (fMacPort != NULL)
  268.     {
  269.         GrafPtr port;
  270.         ::GetPort(&port);    
  271.         ::SetPort(fMacPort);    
  272.         ::SetOrigin(-fMacOrigin.h, -fMacOrigin.v);
  273.         ::SetPort(port);
  274.     }
  275. #endif
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    FW_CPlatformGraphicContext::Reset
  280. //----------------------------------------------------------------------------------------
  281.  
  282. void FW_CPlatformGraphicContext::Reset()
  283. {
  284.     FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(fEnvironment, fFacet->AcquireAggregateClipShape(fEnvironment, NULL)));
  285.     
  286.     PrivReset(NULL, aqClipShape);
  287.     
  288. #ifdef FW_BUILD_MAC
  289.     PrivMacAlignOrigin(fEnvironment);
  290. #endif
  291. }
  292.  
  293. #ifdef FW_BUILD_MAC
  294. //----------------------------------------------------------------------------------------
  295. // FW_CPlatformGraphicContext::PrivMacAlignOrigin
  296. //----------------------------------------------------------------------------------------
  297.  
  298. void FW_CPlatformGraphicContext::PrivMacAlignOrigin(Environment* ev)
  299. {
  300.     FW_CAcquiredODTransform aqContentTransform = fFacet->AcquireContentTransform(ev, NULL);
  301.     FW_CPoint origin(FW_kZeroPoint);
  302.     origin.Transform(ev, aqContentTransform);
  303.     
  304.     ::GetPort(&fMacPort);    
  305.     fMacOrigin.h = fMacPort->portRect.left;
  306.     fMacOrigin.v = fMacPort->portRect.top;
  307.  
  308.     ::SetOrigin(- FW_FixedToInt(origin.x), - FW_FixedToInt(origin.y));
  309. }
  310. #endif
  311.  
  312. //========================================================================================
  313. // CLASS FW_CViewContext
  314. //========================================================================================
  315.  
  316. FW_DEFINE_AUTO(FW_CViewContext)
  317.  
  318. //----------------------------------------------------------------------------------------
  319. // FW_CViewContext::FW_CViewContext
  320. //----------------------------------------------------------------------------------------
  321. // invalidShape is in view content coordinates
  322.  
  323. FW_CViewContext::FW_CViewContext(Environment* ev, FW_CView *view, ODFacet* odFacet, ODShape* invalidShape) :
  324.     FW_CGraphicContext(ev),
  325.     fView(view),
  326.     fFacet(odFacet)
  327. {
  328.     FW_ASSERT(fFacet);
  329.     
  330.     if (fView == NULL)
  331.     {
  332.         FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, odFacet->GetFrame(ev));
  333.         fView = frame->GetContentView(ev);
  334.     }
  335.     
  336.     FW_CAcquiredODTransform aqTransform = PrivAcquireTransform(ev);
  337.     FW_CAcquiredODShape aqClipShape = PrivAcquireClipShape(ev);
  338.     
  339.     // Intersect it with the invalidShape (already in view content coordinates)
  340.     if (invalidShape != NULL)
  341.         aqClipShape->Intersect(ev, invalidShape);
  342.     
  343.     InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet), 
  344.                         aqTransform, 
  345.                         aqClipShape);
  346.  
  347.     FW_END_CONSTRUCTOR
  348. }
  349.  
  350. //----------------------------------------------------------------------------------------
  351. // FW_CViewContext::~FW_CViewContext
  352. //----------------------------------------------------------------------------------------
  353.  
  354. FW_CViewContext::~FW_CViewContext()
  355. {
  356.     FW_START_DESTRUCTOR
  357. }
  358.  
  359. //----------------------------------------------------------------------------------------
  360. // FW_CViewContext::PrivAcquireTransform
  361. //----------------------------------------------------------------------------------------
  362.  
  363. ODTransform* FW_CViewContext::PrivAcquireTransform(Environment* ev)
  364. {
  365.     ODTransform* transform = FW_CopyAndRelease(ev, fView->AcquireViewContentToFrameTransform(ev));
  366.     
  367.     // compute transform to convert view to canvas coordinates 
  368.     FW_CAcquiredODTransform aqFrameTransform = fFacet->AcquireFrameTransform(ev, NULL);
  369.     transform->PostCompose(ev, aqFrameTransform);
  370.     
  371.     return transform;
  372. }
  373.  
  374. //----------------------------------------------------------------------------------------
  375. // FW_CViewContext::PrivAcquireClipShape
  376. //----------------------------------------------------------------------------------------
  377.  
  378. ODShape* FW_CViewContext::PrivAcquireClipShape(Environment* ev)
  379. {
  380.     ODShape* clipShape;
  381.     if (fView->PrivIsTopPrintedView(ev))
  382.     {
  383.         // If I am the top printed view I need to use my extent not my visible bounds
  384.         FW_CRect clipRect(FW_kZeroPoint, fView->GetExtent(ev));    
  385.         clipShape = ::FW_NewODShape(ev, clipRect);
  386.         clipShape->SetGeometryMode(ev, kODLoseGeometry);
  387.     }
  388.     else
  389.     {
  390.         FW_CAcquiredODShape aqAggregateClipShape = fFacet->AcquireAggregateClipShape(ev, NULL);
  391.         
  392.         clipShape = ::FW_NewODShape(ev, fView->GetVisibleBounds(ev));  // visible bounds is in frame coordinates too
  393.         clipShape->SetGeometryMode(ev, kODLoseGeometry);
  394.  
  395.         clipShape->Intersect(ev, aqAggregateClipShape);
  396.  
  397.         //    convert it to view content coordinates
  398.         fView->FrameToViewContent(ev, clipShape);
  399.     }
  400.     
  401.     return clipShape;
  402. }
  403.  
  404. //----------------------------------------------------------------------------------------
  405. //    FW_CViewContext::Reset
  406. //----------------------------------------------------------------------------------------
  407.  
  408. void FW_CViewContext::Reset()
  409. {
  410.     FW_CAcquiredODTransform aqTransform = PrivAcquireTransform(fEnvironment);
  411.     FW_CAcquiredODShape aqClipShape = PrivAcquireClipShape(fEnvironment);
  412.     
  413.     PrivReset(aqTransform, aqClipShape);
  414. }
  415.  
  416.